package main.com.votes.dao;

import main.com.votes.model.User;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao extends BaseDAO {

    //    查询用户名是否被占用
    public User getUserByUsername(String username) {
        String sql = "SELECT * FROM user WHERE username = ?";
        return super.select(sql, new Object[]{username});
    }

//    注册用户
    public int registerUser(String username,String password) throws SQLException {
        String sql = "insert into user (username,password) values (?, ?)";
        return super.update(sql, new Object[]{username, password});
    }

    @Override
    public User rowMapper(ResultSet rs) throws SQLException {
        User user = new User();
        user.setId(rs.getInt(1));
        user.setUsername(rs.getString(2));
        user.setPassword(rs.getString(3));
        user.setType(rs.getInt(4));
        user.setStatus(rs.getInt(5));
        return user;
    }
}
